﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using CoreEx.Common.Linq;
using LinFu.IoC.Configuration;

namespace CoreEx.Database.Linq.Implementation
{
    [Implements(typeof(ILoadExpressionResolver))]
    public class LoadExpressionResolver : ExpressionVisitor, ILoadExpressionResolver
    {
        private Type _declaringType;
        
        private MemberExpression _memberInfo;
        
        public MemberExpression GetMemberInfo(Expression expression, Type declaringType)
        {
            _memberInfo = null;
            _declaringType = declaringType;
            Visit(expression);
            return _memberInfo;
        }

        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            if (m.Member.DeclaringType == _declaringType)
                _memberInfo = m;
            return base.VisitMemberAccess(m);
        }


    }
}
